package com.zksb.controller;

import com.zksb.entity.Result;
import com.zksb.entity.User;
import com.zksb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    public UserController() {
        System.out.println("UserController.....");
    }

    @RequestMapping("test")
    public Object test() {
        return "ok";
    }

    @RequestMapping("/{id}")
    public Object get(@PathVariable("id") Integer id) {
        User u = userService.get(id);

        return Result.success(u);
    }

    @PostMapping
    public Object add(@RequestBody User user) {
        int row = userService.add(user);
        System.out.println(user);
        return Result.success(user);
    }


}
